package com.property.demo.repository;

import com.property.demo.model.ManagerCommunity;
import com.property.demo.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ManagerCommunityRepository extends JpaRepository<ManagerCommunity, Long> {
    
    List<ManagerCommunity> findByManager(User manager);
    
    @Query("SELECT mc.community.id FROM ManagerCommunity mc WHERE mc.manager.id = :managerId")
    List<Long> findCommunityIdsByManagerId(@Param("managerId") Long managerId);
    
    @Query("SELECT mc.community.id FROM ManagerCommunity mc WHERE mc.manager.username = :username")
    List<Long> findCommunityIdsByManagerUsername(@Param("username") String username);
    
    boolean existsByCommunityIdAndManagerId(Long communityId, Long managerId);
    
    boolean existsByCommunityIdAndManager_Username(Long communityId, String username);
} 